#include <iostream>
#include <stdexcept>
#include <string>
#include <istream>
#include <sstream>
#include <fstream>
#include <cstdlib>

#include "utils.h"


  typedef adjacency_list < vecS, vecS, undirectedS, no_property, property < edge_weight_t, int > > Graph;
  typedef graph_traits < Graph >::edge_descriptor Edge;
  typedef graph_traits < Graph >::vertex_descriptor Vertex;
  typedef std::pair<int, int> E;



int main(int argc, char **argv)
{
	//Graph graph;
	//Algo algo;

  using namespace boost;

	if (argc != 4)
	{
		
	}

	int graph_type = toInt(argv[2]);
	int algo_type = toInt(argv[3]);

//	Graph::Algorithm 
	int type;

	if (graph_type == 0)
	{
		std::cout << "Using Complete Graph\n";
	}
	else if (graph_type == 1)
	{
		std::cout << "Using delaunay triangle\n";
	}
	else
	{
		std::cout << "Graph type error: 0 complete graph, 1 delaunay triangle\n";
		return EXIT_SUCCESS;
	}

	std::string plName = argv[1];
	std::vector<std::string> t = tokenize(plName, "-.");
	int size = toInt(t.at(t.size() - 2));

	std::stringstream mss;
	mss << "mst-" << size << ".svg";
	std::string mstName = mss.str();

/*	Graph graph;
	graph.loadPoints(plName);
	graph.calculateMST(type);
	graph.saveMST(mstName);
*/
	return EXIT_SUCCESS;
}





void loadPoints(const std::string &filename)
{
	Vertex* vertexArray;
	
	int pos = 0, lineNo = 1;

	//beginTimer();

	std::ifstream fstr(filename.c_str());
	if (!fstr.is_open())
		throw std::runtime_error("Unable to open filename " + filename);

	std::string line;
	try
	{
		while (getline(fstr, line))
		{
			if (lineNo == 1)
			{
				int size = toInt(line);
				vertexArray = new Vertex[size];
			}
			else
			{
				std::vector<std::string> tokens = tokenize(line);
				vertexArray[pos++] = Vertex(toFloat(tokens.at(0)), toFloat(tokens.at(1)));
			}

			lineNo++;
		}
	}
	catch (...)
	{
		throw std::runtime_error("Bad file input at line " + lineNo);
	}

#if DEBUG
	std::cerr << size << "\n";
	for (int i = 0; i < size; i++)
		std::cerr << "Vertex: " << vertexArray[i].p.x << ", " << vertexArray[i].p.y << "\n";
#endif

	fstr.close();
/*	
	endTimer();
	std::cout << "Point loading time: " << getTime() << "ms\n";*/
}

